import * as THREE from 'three';
import { createFlame } from './flame';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import {tag} from './tag'
// import {tag} from "./tag.js"
const model = new THREE.Group();
const loader = new GLTFLoader();
loader.load('/有光源.glb',(gltf)=>{
    model.add(gltf.scene);
    // 将 粮仓P_06和P_05标注上火焰
    const granaryFlame = function(name){
        const gltfObj = gltf.scene.getObjectByName(name)
        const pos = new THREE.Vector3()
        gltfObj.getWorldPosition(pos)
        const flame = createFlame()
        flame.position.copy(pos)
        if(gltfObj.parent.name === "立筒仓"){
            flame.position.y+= 36
        }else if(gltfObj.parent.name === "浅圆仓"){
            flame.position.y+= 20
        }else if(gltfObj.parent.name === "平房仓"){
            flame.position.y+=  17
        }
        flame.position.y -= 4
        const fireTip = tag("fireTip")
        const fireTipCopy =  fireTip.clone()
        flame.add(fireTipCopy)
        fireTipCopy.position.y += 40;
        fireTipCopy.scale.set(0.5,0.5,0.5)
        fireTipCopy.rotateY( Math.PI * 0.5 );
        flame.tag = fireTipCopy
        return flame
    }
    const P_06flame = granaryFlame("P_06")
    model.add(P_06flame)
    setTimeout(() => {
        P_06flame.stop()
        model.remove(P_06flame)
        P_06flame.remove(P_06flame.tag)
    }, 3000);
    setTimeout(() => {
        const P_05flame = granaryFlame("P_05")
        model.add(P_05flame)
    }, 1000);
})
export {model};